
#!/bin/bash
#Log颜色处理-------------start
function infolog(){
    echo -e Log: "\033[32m$1\033[0m"
}

#输出报错log
function errorlog(){
    echo -e Error: "\033[01;31m$1\033[0m"
}

#输出报错log并停止运行
function errorlogExit(){
    echo -e Error: "\033[01;31m$1\033[0m"
    echo -e Error: "\033[01;31m打包失败\033[0m"
    exit
}

###获取当前脚步路径......
_CPath=$(pwd)
#echo "scriptPath1: "$(cd `dirname $0`; pwd)
#echo "scriptPath2: "$(pwd)
#echo "scriptPath4: "$(cd $(dirname ${BASH_SOURCE:-$0});pwd)

###获取当前时间......
_SDate=$(date +%Y.%m.%d_%H.%M.%S)


userName=$1
echo userName,,.....${userName}
appPackages=$2
echo appPackages,,.....${appPackages}
buildType=$3
echo buildType,,.....${buildType}
buildId=$4
echo buildId,,.....${buildId}



userWorkRoot="/Users/xia9000/work/app2build/${userName}.${buildType}.${appPackages}"



macShareD_app2build="/Volumes/VMware Shared Folders/macShareD/app2build"
 

echo "#如果文件夹存在，删除创建文件夹"
if [ -d ${userWorkRoot} ]; then
    echo "#件夹存在，删除文件夹..........."
    rm -rf ${userWorkRoot}
fi
mkdir ${userWorkRoot}



array=(${appPackages//+/ })
for var in ${array[@]}
do
    path1="${macShareD_app2build}/${userName}/${var}/"
    path2="${userWorkRoot}/${var}"
    echo "开始考备...${path1}.........${path2}"
    cp -R "${path1}" "${path2}"
   
done

cp -f "${macShareD_app2build}/sign.keystore" "${userWorkRoot}/sign.keystore"
cp -f "${macShareD_app2build}/app.ipa" "${userWorkRoot}/app.ipa"
cp -f "${macShareD_app2build}/app.apk" "${userWorkRoot}/app.apk"

cp -f "${macShareD_app2build}/java_app2SignTools.jar" "/Users/xia9000/work/app2build/root/java_app2SignTools.jar"



java -jar /Users/xia9000/work/app2build/root/java_app2SignTools.jar ${userWorkRoot} ${buildType} ${buildId}
